---
title: gluestack-ui Alert Component | Installation, Usage, and API

description: Status indicators notify users of important system, feature, or page conditions that require attention.

pageTitle: Alert

pageDescription: Status indicators notify users of important system, feature, or page conditions that require attention.

showHeader: true
---

import { Meta } from '@storybook/addon-docs';

<Meta title="with-nativewind/Components/Feedback/Alert" />

import {
  Alert,
  AlertIcon,
  AlertText,
  InfoIcon,
  CloseIcon,
  RepeatIcon,
  Icon,
  VStack,
  HStack,
  Text,
  Heading,
  Button,
  ButtonText,
  Input,
  InputField,
  InputSlot,
  InputIcon
} from '../../core-components/nativewind';
import { Bomb, EyeIcon, EyeOffIcon } from "lucide-react-native";
import { transformedCode } from '../../utils';
import {
  AppProvider,
  CodePreview,
  Table,
  InlineCode,
  TableContainer,
  Tabs
} from '@gluestack/design-system';
import { CollapsibleCode } from '@gluestack/design-system';
import Wrapper from '../../core-components/nativewind/Wrapper';
import AnatomyImage from '../../extra-components/nativewind/AnatomyImage';

This is an illustration of **Alert** component.

<Wrapper>
  <CodePreview
    _rendererWrapper={{ px: '$2.5' }}
    showComponentRenderer={true}
    showArgsController={true}
    metaData={{
      code: `
        <Alert {...props}>
          <AlertIcon as={InfoIcon} />
          <AlertText>
            Description of alert!
          </AlertText>
        </Alert>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: {
        Alert,
        AlertIcon,
        AlertText,
        Wrapper,
        InfoIcon,
      },
      argsType: {
        action: {
          control: 'select',
          options: ['success', 'info', 'error', 'warning', 'muted'],
          default: 'info',
        },
        variant: {
          control: 'select',
          options: ['solid', 'outline'],
          default: 'solid',
        },
      },
    }}
  />
</Wrapper>

<br />

## Installation

<Tabs value="cli" type="section">
<Tabs.TabList>
      <Tabs.Tab value="cli">
        <Tabs.TabTitle>CLI</Tabs.TabTitle>
      </Tabs.Tab>
     <Tabs.Tab value="manual">
        <Tabs.TabTitle>Manual</Tabs.TabTitle>
     </Tabs.Tab>
  </Tabs.TabList>
  <Tabs.TabPanels>
    <Tabs.TabPanel value="cli">
<>

### Run the following command:
  ```bash
  npx gluestack-ui add alert
  ```
</>
    </Tabs.TabPanel>
    <Tabs.TabPanel value="manual"> 
<>

### Step 1: Install the following dependencies:

```bash

npm i @gluestack-ui/alert

```

### Step 2: Copy and paste the following code into your project.

<CollapsibleCode>

```jsx 
%%-- File: core-components/nativewind/alert/index.tsx --%% 
```

</CollapsibleCode>

### Step 3: Update the import paths to match your project setup.
</>
    </Tabs.TabPanel>
  </Tabs.TabPanels>
</Tabs>

## API Reference

To use this component in your project, include the following import statement in your file.

```jsx
import { Alert, AlertIcon, AlertText } from '@/components/ui/alert';
```

<AnatomyImage mobileUrl='https://i.imgur.com/gdI4o2w.png' webUrl='https://i.imgur.com/f8hHiIJ.png' classNameStyle='aspect-[513/375] md:aspect-[736/259]' />

```jsx
export default () => (
  <Alert>
    <AlertIcon />
    <AlertText />
  </Alert>
);
```

### Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

#### Alert

Contains all alert related layout style props and actions. It inherits all the properties of React Native's [View](https://reactnative.dev/docs/pressable) component.

#### AlertIcon

It inherits all the properties of React Native's [View](https://reactnative.dev/docs/view) component.

#### AlertText

Contains all spinner related layout style props and actions. It inherits all the properties of React Native's [Text](https://reactnative.dev/docs/text) component.

### Props

Alert component is created using View component from react-native. It extends all the props supported by [React Native View](https://reactnative.dev/docs/view#props).

#### Alert

<>
  <TableContainer>
    <Table>
      <Table.THead>
        <Table.TR>
          <Table.TH>
            <Table.TText>Name</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Value</Table.TText>
          </Table.TH>
          <Table.TH>
            <Table.TText>Default</Table.TText>
          </Table.TH>
        </Table.TR>
      </Table.THead>
      <Table.TBody>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>action</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>error | warning | success | info | muted</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>info</Table.TText>
          </Table.TD>
        </Table.TR>
        <Table.TR>
          <Table.TD>
            <Table.TText>
              <InlineCode>variant</InlineCode>
            </Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>solid | outline</Table.TText>
          </Table.TD>
          <Table.TD>
            <Table.TText>solid</Table.TText>
          </Table.TD>
        </Table.TR>
      </Table.TBody>
    </Table>
  </TableContainer>
</>

### Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

#### Alert with CTA

<Wrapper>
  <CodePreview
    showComponentRenderer={true}
    showArgsController={false}
     _rendererWrapper={{
      alignItems: 'stretch',
      padding: 20
    }}
    metaData={{
      code: `
        <Alert
          action="success"
          className="gap-4 max-w-[585px] w-full self-center items-start min-[400px]:items-center"
        >
          <VStack className="gap-4 min-[400px]:flex-row justify-between flex-1 min-[400px]:items-center">
            <AlertText className="font-semibold text-typography-900" size="sm">
              Verify your phone number to create an API key
            </AlertText>
            <Button size="sm">
              <ButtonText>Start verification</ButtonText>
            </Button>
          </VStack>
          <Icon as={CloseIcon} />
        </Alert>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: {
        Alert,
        AlertText,
        Wrapper,
        VStack,
        Icon,
        CloseIcon,
        Button,
        ButtonText
      },
      argsType: {},
    }}
  />
</Wrapper>

#### Alert on cloud sync

<Wrapper>
  <CodePreview
    _rendererWrapper={{
      alignItems: 'stretch',
      padding: 20
    }}
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        <Alert
          action="warning"
          className="gap-4 max-w-[516px] w-full flex-row flex py-4 items-start self-center"
        >
          <AlertIcon as={RepeatIcon} className="mt-1" />
          <HStack className="justify-between flex-1 items-center gap-1 sm:gap-8">
            <VStack className="flex-1">
              <Text className="font-semibold text-typography-900">
                Sync is disabled
              </Text>
              <AlertText className="text-typography-900" size="sm">
                Enable cloud sync to help safeguard your data
              </AlertText>
            </VStack>
            <Button size="xs">
              <ButtonText>Turn on</ButtonText>
            </Button>
          </HStack>
        </Alert>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: {
        Alert,
        AlertIcon,
        AlertText,
        Wrapper,
        HStack,
        VStack,
        RepeatIcon,
        Button,
        ButtonText,
        Text
      },
      argsType: {},
    }}
  />
</Wrapper>

#### Warning alert

<Wrapper>
  <CodePreview
    _rendererWrapper={{
      padding: 20
    }}
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        <Alert action="error" className="gap-3">
          {/* Bomb is imported from 'lucide-react-native' */}
          <AlertIcon as={Bomb} size="lg" />
          <AlertText className="text-typography-900" size="sm">
            <Text className="mr-2 font-semibold text-typography-900">
              Heads up:
            </Text>
            Once done, this action cannot be undone
          </AlertText>
        </Alert>
      `,
      transformCode: (code) => {
        return transformedCode(code);
      },
      scope: {
        Alert,
        AlertIcon,
        AlertText,
        Wrapper,
        Text,
        Bomb
      },
      argsType: {},
    }}
  />
</Wrapper>

#### Alert on confirm password modal

<Wrapper>
  <CodePreview
    _rendererWrapper={{
      padding: 20
    }}
    showComponentRenderer={true}
    showArgsController={false}
    metaData={{
      code: `
        function Example() {
          const [showPassword, setShowPassword] = React.useState(false);
          const handleState = () => {
            setShowPassword((showState) => {
              return !showState;
            });
          };
          return (
            <VStack className="gap-5 sm:gap-8 p-6 sm:p-9 border border-outline-200 bg-background-0 rounded-xl shadow-hard-5 w-full max-w-[423px]">
              <VStack className="items-center gap-1">
                <Heading size="xl">Confirm our password?</Heading>
                <Text>johnsmith@gmail.com</Text>
              </VStack>
              <VStack className="gap-3 sm:gap-5">
                <Input className="rounded-md" size="sm">
                  <InputField
                    type={showPassword ? 'text' : 'password'}
                    placeholder="Enter password"
                  />
                  <InputSlot className="mr-3" onPress={handleState}>
                    {/* EyeIcon, EyeOffIcon are both imported from 'lucide-react-native' */}
                    <InputIcon
                      size="xs"
                      as={showPassword ? EyeIcon : EyeOffIcon}
                      className="stroke-background-600"
                    />
                  </InputSlot>
                </Input>
                <Button className="w-full rounded-md" size="sm">
                  <ButtonText>Confirm</ButtonText>
                </Button>
              </VStack>
              <Alert className="items-start" action="muted">
                <AlertIcon as={InfoIcon} size="xs" className="stroke-background-500" />
                <AlertText className="text-typography-600" size="xs">
                  Minimum 8 characters, with at least 1 uppercase, 1 lowercase, and 1
                  number required.
                </AlertText>
              </Alert>
            </VStack>
          );
        };
      `,
      transformCode: (code) => {
        return transformedCode(code, 'function', 'Example');
      },
      scope: {
        Alert,
        AlertIcon,
        AlertText,
        Wrapper,
        HStack,
        VStack,
        Button,
        ButtonText,
        Text,
        Heading,
        Input,
        InputField,
        InputSlot,
        InputIcon,
        EyeIcon,
        EyeOffIcon,
        InfoIcon
      },
      argsType: {},
    }}
  />
</Wrapper>
